﻿/*
-----------------------------------------------------------------------------
This source file is part of Cell Cloud.

Copyright (c) 2009-2012 Cell Cloud Team - cellcloudproject@gmail.com

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-----------------------------------------------------------------------------
*/

#ifndef CellMessageAcceptor_h
#define CellMessageAcceptor_h

#include "CellPrerequisites.h"
#include "CellInetAddress.h"
#include "CellMessageService.h"

namespace cell
{
/** \addtogroup Core
 *  @{
 */
/** \addtogroup General
 *  @{
 */

/// 会话列表数据类型。
typedef std::vector<Session*> SessionList;
/// 会话 ID 列表。
typedef std::vector<ulong> SessionIdList;

/** 消息接收器。
@author
	Jiangwei Xu
*/
class _CellExport MessageAcceptor : public MessageService
{
public:
	/** 默认构造函数。
	*/
	MessageAcceptor(void);

	/** 析构函数。
	*/
	virtual ~MessageAcceptor(void);

public:
	/** 绑定消息接收服务到指定端口。
	*/
	virtual bool bind(uint port) = 0;

	/** 绑定消息接收服务到指定地址。
	*/
	virtual bool bind(const InetAddress& addr) = 0;

	/** 解绑当前绑定的服务地址。
	*/
	virtual void unbind(void) = 0;

	/** 关闭指定会话。
	*/
	virtual void close(Session* session) = 0;

	/** 列举所有会话。
	*/
	virtual void listSessionIds(SessionIdList& list) = 0;

	/** 返回指定 ID 的 Session
	*/
	virtual Session* getSession(ulong id) = 0;

	/** 设置最大连接数。
	*/
	virtual void setMaxConnectNum(int num) = 0;

	/** 返回最大连接数。
	*/
	virtual int getMaxConnectNum(void) = 0;

	/** 返回当前连接数。
	*/
	virtual int getConnectNum(void) = 0;

public:
	/** 门闩
	*/
	bool latch;
};

/** @} */
/** @} */
} // end namespace cell

#endif // CellMessageAcceptor_h
